package com.oos.zone.wechat.mp.service.handler;

import lombok.extern.log4j.Log4j2;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Service;

import java.util.Locale;
import java.util.concurrent.CompletableFuture;

/**
 * 功能描述：普通消息处理器
 *
 * @author 拓金辉
 * @version 1.0
 * @date 2021-08-09 09:16:24
 */
@Log4j2
@Service
public class WxMpStandardMessageHandler extends AbstractWxMpMessageHandler {

    @Override
    public WxMpXmlOutMessage handle0() {
        final String msgType = wxMessage.getMsgType();
        if (msgType == null || msgType.isEmpty()) {
            return defaultTextMessage;
        }
        switch (msgType.toLowerCase(Locale.ROOT)) {
            case "text":
                return text();
            case "image":
                return image();
            case "voice":
                return voice();
            case "video":
                return video();
            case "shortvideo":
                return shortvideo();
            case "location":
                return location();
            case "link":
                return link();
            case "file":
                return file();
            default:
                log.error("\n\n【事件类型未处理】\n\n {}", wxMessage.toString());
                return defaultTextMessage;
        }
    }

    public WxMpXmlOutMessage text() {
        CompletableFuture.runAsync(() -> log.info("文本消息\n"), executor);
        return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).content(wxMessage.getContent()).build();
    }

    public WxMpXmlOutMessage image() {
        CompletableFuture.runAsync(() -> log.info("图片消息\n"), executor);
        return defaultTextMessage;
    }

    public WxMpXmlOutMessage voice() {
        CompletableFuture.runAsync(() -> log.info("语音消息\n"), executor);
        return defaultTextMessage;
    }

    public WxMpXmlOutMessage video() {
        CompletableFuture.runAsync(() -> log.info("视频消息\n"), executor);
        return defaultTextMessage;
    }

    public WxMpXmlOutMessage shortvideo() {
        CompletableFuture.runAsync(() -> log.info("小视频消息\n"), executor);
        return defaultTextMessage;
    }

    public WxMpXmlOutMessage location() {
        CompletableFuture.runAsync(() -> log.info("地理位置消息\n"), executor);
        return defaultTextMessage;
    }

    public WxMpXmlOutMessage link() {
        CompletableFuture.runAsync(() -> log.info("链接消息\n"), executor);
        return defaultTextMessage;
    }

    public WxMpXmlOutMessage file() {
        CompletableFuture.runAsync(() -> log.info("文件消息\n"), executor);
        return defaultTextMessage;
    }

}
